/*
* Copyright (C) 2020 Tianjin KYLIN Information Technology Co., Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/&gt;.
*
*/
#ifndef SCROLLINGAREAWIDGETMAJOR_H
#define SCROLLINGAREAWIDGETMAJOR_H

#include <QObject>
#include <QWidget>
#include <QSlider>
#include <QHBoxLayout>
#include <QLabel>
#include <QIcon>
#include <QDebug>
#include <QGSettings>
#include <QEvent>
#include <QMouseEvent>
#include <QProcess>
#include <QPainter>
#include "../commondata.h"
#include "../gsettingmanager.h"
#include "../dbusmanager.h"

#define HANDSLIDERSIZE 13


class SliderButtonMajor;

class ScrollingAreaWidgetMajor : public QWidget
{
    Q_OBJECT
public:
    ScrollingAreaWidgetMajor(QWidget *parent = nullptr);

private:
    void initMemberVariable();
    void initGsetting();
    void initSlideStatus();
    void initLayout();
    void initConnect();
    void setVolumeStatusIcon(int value);
    void setLightStatusIcon(int value);

private:
    QVBoxLayout *m_pVMainLayout;
    QString m_bModelStatus;
    QWidget     *m_pVolumeWidget;
    QLabel      *m_pVolumeIconLabel;
    SliderButtonMajor     *m_pVolumeSlide;
    QHBoxLayout *m_pHVolumeLayout;

    QWidget     *m_pBrightNessWidget;
    QLabel      *m_pBrightIconLabel;
    SliderButtonMajor     *m_pBrightSlide;
    QHBoxLayout *m_pBrightLayout;

    QString m_QFocus;

protected:
    bool eventFilter(QObject *watched, QEvent *event);
    void keyPressEvent(QKeyEvent *event);

private slots:
    void setSliderValue(QString key);
    void setVolumeSlideSlots(int value);
    void setBrightSlideSlots(int value);
};

class SliderButtonMajor : public QWidget
{
    Q_OBJECT
public:
    SliderButtonMajor();
    ~SliderButtonMajor();

    int m_touchX = 0;
    int m_saveData = 0;
    QColor   m_themeColor;

    void setValue(int value);

protected:
    void paintEvent(QPaintEvent *);
    void mouseMoveEvent(QMouseEvent *event);
    void mousePressEvent(QMouseEvent *event);

private:
    void updatePaint(int value);
    void proportionHandle(int value);
    void updateThemeColor();

Q_SIGNALS:
    void dataChange(int value);
    void keyPressUp();
    void keyPressDown();


};

#endif // SCROLLINGAREAWIDGETMAJOR_H
